// Package 剑指_Offer_26__树的子结构 main
// @Title 剑指_Offer_26__树的子结构
// @Description
// @Author  == 琳琳也叫王木木 ==  2022-02-09 13:12
// @Create  2022-02-09 13:12
package main

//Definition for a binary tree node.
type TreeNode struct {
	Val   int
	Left  *TreeNode
	Right *TreeNode
}

// isSubStructure
// @Description: 判断B是否是A的子结构
// @param A
// @param B
// @return bool
func isSubStructure(A *TreeNode, B *TreeNode) bool {
	return (A != nil && B != nil) && process(A, B) || isSubStructure(A.Left, B) || isSubStructure(A.Right, B)
}

func process(A *TreeNode, B *TreeNode) bool {
	if B == nil {
		return true
	}
	if A == nil || A.Val != B.Val {
		return false
	}
	return process(A.Left, B.Left) && process(A.Right, B.Right)
}
